//
//  DDCartTableCell.m
//  Dingdong
//
//  Created by 程强 on 16/11/15.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDCartTableCell.h"

@interface DDCartTableCell()
@property (strong, nonatomic) NSString *editLastCount;
@end

@implementation DDCartTableCell
- (void)awakeFromNib {
    [super awakeFromNib];
    self.iconBgView.layer.borderColor = RGBColor(238, 238, 238).CGColor;
    self.iconBgView.layer.borderWidth = 1.0;
    
    self.countBarBgView.layer.borderColor = RGBColor(238, 238, 238).CGColor;
    self.countBarBgView.layer.borderWidth = 1.0;
}
- (IBAction)reduseClick:(id)sender
{
    NSInteger count = [self.countTxf.text integerValue];
    NSInteger lastCount = count;
    if (count>1) {
        count -=1;
    }
    self.countTxf.text = [NSString stringWithFormat:@"%ld",count];
    if (self.numHandler) {
        self.numHandler(self.countTxf.text,FormatString(@"%ld", lastCount));
    }
}
- (IBAction)addClick:(id)sender
{
    NSInteger count = [self.countTxf.text integerValue];
    NSInteger lastCount = count;
    count +=1;
    self.countTxf.text = [NSString stringWithFormat:@"%ld",count];
    if (self.numHandler) {
        self.numHandler(self.countTxf.text,FormatString(@"%ld", lastCount));
    }
}
- (IBAction)selectCartClick:(id)sender
{
    if (self.handler) {
        self.handler();
    }
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    self.editLastCount = textField.text;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (self.numHandler) {
        self.numHandler(self.countTxf.text,self.editLastCount);
    }
}
- (void)userCartSelect:(CartSelectedHandle)handle
{
    self.handler = handle;
}
- (void)userModifyNumber:(CartNumHandle)handle
{
    self.numHandler = handle;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
